package com.sskj.lib.util;

import android.app.Activity;
import android.text.TextUtils;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.lib.R;
import com.sskj.lib.RConfig;
import com.sskj.lib.bean.UserData;

public class AppInnerCheckUtil {

    /**
     * 验证手机号
     *
     * @param userData
     * @return
     */
    public static boolean checkTel(Activity activity, UserData userData) {
        if (TextUtils.isEmpty(userData.getTel())) {
            TipUtil.getTip(activity, activity.getString(R.string.lib_app_check6),
                    activity.getString(R.string.lib_app_check7), () -> {
                        if (activity.getClass().getName().contains("SecurityCenterActivity")) {
                            ARouter.getInstance().build(RConfig.MINE_BIND_MOBILE).navigation();
                        } else {
                            ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();
                        }
                    }).show();
            return false;
        }
        return true;
    }

    /**
     * 验证实名认证
     *
     * @param userData
     * @return
     */
    public static boolean checkAuth(Activity activity, UserData userData) {
        if (!checkTel(activity, userData)) {
            return false;
        }
        if (userData.getStatus() == 3) {
            return true;
        }

        if (userData.getStatus() == 2) {
            TipUtil.getTip(activity, activity.getString(R.string.lib_app_check1), activity.getString(R.string.lib_app_check2),
                    activity.getString(R.string.lib_app_check3),
                    () -> {
                    }).show();
            return false;
        } else {
            TipUtil.getTip(activity, activity.getString(R.string.lib_app_check4),
                    activity.getString(R.string.lib_app_check5),
                    () -> {
                        if (activity.getClass().getName().contains("SecurityCenterActivity")) {
                            ARouter.getInstance().build(RConfig.MINE_CERTIFICATION).navigation();
                        } else {
                            ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();
                        }
                    }).show();
            return false;
        }
    }


    /**
     * 验证支付密码
     *
     * @param userData
     * @return
     */
    public static boolean checkTradePwd(Activity activity, UserData userData) {

        if (!checkAuth(activity, userData)) {
            return false;
        }
        if (TextUtils.isEmpty(userData.getTradePwd())) {
            TipUtil.getTip(activity, activity.getString(R.string.lib_app_check8),
                    activity.getString(R.string.lib_app_check9), () -> {
                        if (activity.getClass().getName().contains("SecurityCenterActivity")) {
                            ARouter.getInstance().build(RConfig.MINE_SET_PAY_PWD).navigation();
                        } else {
                            ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();
                        }
                    }).show();
            return false;
        }
        return true;
    }

    /**
     * 验证支付方式
     *
     * @param userData
     * @return
     */
    public static boolean checkPayType(Activity activity, UserData userData) {

        if (!checkTradePwd(activity, userData)) {
            return false;
        }
        if (userData.getIshavePay() == 0) {
            TipUtil.getTip(activity, activity.getString(R.string.lib_app_check_pay_type),
                    activity.getString(R.string.lib_app_check_add), () -> {
                        if (activity.getClass().getName().contains("SecurityCenterActivity")) {
                            ARouter.getInstance().build(RConfig.MINE_PAY_TYPE_UPDATE).navigation();
                        } else {
                            ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();
                        }
                    }).show();
            return false;
        }
        return true;
    }


    /**
     * 验证商家
     *
     * @param userData
     * @return
     */
    public static boolean checkShop(Activity activity, UserData userData) {
        if (!checkPayType(activity, userData)) {
            return false;
        }
        if (!userData.isShop()) {
            TipUtil.getTip(activity, activity.getString(R.string.lib_app_check_shop),
                    activity.getString(R.string.lib_app_check5), () -> {
                        if (activity.getClass().getName().contains("SecurityCenterActivity")) {
                            ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();
                        } else {
                            ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();
                        }
                    }).show();
            return false;
        }
        return true;
    }
}
